//
//  BaseTableViewController.swift
//  WeiBo
//
//  Created by wukeng-mac on 16/8/22.
//  Copyright © 2016年 wukeng. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController {
    lazy var isLogin : Bool = UserAccountViewModel.single.isLogin
    lazy var v : visitorView = visitorView.VisitorView()
    
    override func loadView() {
        isLogin ? super.loadView() : setUpVisitorView()
        setUpNavigationItems()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
}

// MARK: - 设置UI界面
extension BaseTableViewController{
    private func setUpVisitorView(){
        self.view = v
        v.registerBtn.addTarget(self, action: #selector(BaseTableViewController.registerBtnClick), forControlEvents: .TouchUpInside)
        v.loginBtn.addTarget(self, action: #selector(BaseTableViewController.LoginBtnClick), forControlEvents: .TouchUpInside)
    }
    //MARK:- 设置导航栏左右的item
    private func setUpNavigationItems(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: #selector(BaseTableViewController.registerBtnClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: #selector(BaseTableViewController.LoginBtnClick))
    }
}


extension BaseTableViewController{
    @objc private func registerBtnClick()  {
        print("registerBtnClick")
    }
    
    @objc private func LoginBtnClick()  {
        LoginOAuth()
    }
    private func LoginOAuth() {
        let oAuthVC = OAuthViewController()
        
        let oAuthNavi = UINavigationController(rootViewController: oAuthVC)
        
        presentViewController(oAuthNavi, animated: true, completion: nil)
        
    }
}






